package com.hrt.datasender.web.bcdevice;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import com.btcode.web.core.annotation.RequestMapping;
import com.btcode.web.core.controller.Controller;
import com.hrt.common.web.DSRequestUnit;
import com.hrt.datasender.datadao.model.BcDevicesModel;
import com.hrt.datasender.datadao.service.BcDeviceService;

/**
 * 设备控制器
 * 
 * @author gislin
 *
 */
@RequestMapping(path = "BCDevice")
public class BCDeviceController extends Controller {

    @RequestMapping(path = "getList")
    public void getList(ServletRequest arg0, ServletResponse arg1) throws IOException {

        List<BcDevicesModel> devices = BcDeviceService.getInstance().getDevices();

        success(devices);
    }

    @RequestMapping(path = "create")
    public void saveModel(ServletRequest arg0, ServletResponse arg1) throws IOException {

        BcDevicesModel model = DSRequestUnit.getModel(BcDevicesModel.class);
        model = BcDeviceService.getInstance().create(model);

        success(model);
    }

    @RequestMapping(path = "delete")
    public void delete(ServletRequest arg0, ServletResponse arg1) throws IOException {
        String id = DSRequestUnit.getString("id");
        BcDeviceService.getInstance().delete(id);
        success("");
    }

    @RequestMapping(path = "getModel")
    public void getModel(ServletRequest arg0, ServletResponse arg1) throws IOException {
        String id = DSRequestUnit.getString("id");
        BcDevicesModel model = BcDeviceService.getInstance().getModel(id);
        success(model);

    }

    @RequestMapping(path = "update")
    public void update(ServletRequest arg0, ServletResponse arg1) throws IOException {

        BcDevicesModel model = DSRequestUnit.getModel(BcDevicesModel.class);
        BcDeviceService.getInstance().update(model);
        success("");
    }
}
